package com.lb.shopguide.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lb.shopguide.R;
import com.lb.shopguide.constants.AppConstant;
import com.lb.shopguide.entity.CouponBean;
import com.lb.shopguide.util.lb.BizUtil;

import java.util.List;

/**
 * Created by kang on 2017/10/18.
 */

public class AdapterTicket extends BaseQuickAdapter<CouponBean, BaseViewHolder> {
    public AdapterTicket(@LayoutRes int layoutResId, @Nullable List<CouponBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CouponBean item) {
        View view = helper.itemView;

        ImageView ivBack = view.findViewById(R.id.iv_back);
        TextView tvPrice = view.findViewById(R.id.tv_price);
        TextView tvShopName = view.findViewById(R.id.tv_shop_name);
        TextView tvTickName = view.findViewById(R.id.tv_ticket_name);
        TextView tvTicketTime = view.findViewById(R.id.tv_ticket_time);
        TextView tvDesc = view.findViewById(R.id.tv_desc);

        tvShopName.setText(item.getStoreName());
        tvTicketTime.setText("有效期：" + item.getStartTime() + "-" + item.getEndTime());
        tvTickName.setText(item.getTypeName());
        switch (item.getTypeCode()) {
            // TODO: 2018/9/20 这边实现了，现金券，折扣券，其余券没有实现
            case AppConstant.TYPE_XIANJIN_TICKET:
                tvDesc.setText("使用说明：" + item.getUseDesc());
//                tvTickName.setText("现金券");
                tvPrice.setText("￥" + item.getMoneyQuota());
                ivBack.setImageResource(R.drawable.iv_xianjin_ticket);
                break;
            case AppConstant.TYPE_MANDI_TICKET:
                tvDesc.setText("使用说明：" + item.getUseDesc());
//                tvTickName.setText("满抵券");
                tvPrice.setText("￥" + item.getDeductQuota());
                ivBack.setImageResource(R.drawable.iv_mandi_ticket);
                break;
            case AppConstant.TYPE_ZHEKOU_TICKET:
                tvDesc.setText("使用说明：" + item.getUseDesc());
                tvPrice.setText(item.getDiscountQuota() + "折");
                ivBack.setImageResource(R.drawable.iv_zhekou_ticket);
                break;
            case AppConstant.TYPE_HUOQI_TICKET:
                tvDesc.setText("使用说明：" + item.getUseDesc());
//                tvTickName.setText("活期券");
                tvPrice.setText("￥" + item.getMoneyQuota());
                ivBack.setImageResource(R.drawable.iv_huoqi_ticket);
                break;
            case AppConstant.TYPE_DANPIN_TICKET:
                tvDesc.setText("使用说明：" + item.getUseDesc());
//                tvTickName.setText("单品券");
                tvPrice.setText("￥" + item.getMoneyQuota());
                ivBack.setImageResource(R.drawable.iv_danpin_ticket);
                break;
            case AppConstant.TYPE_UNABLE_TICKET:
                break;
        }
        if (item.getTypeCode() != AppConstant.TYPE_XIANJIN_TICKET) {
            SpannableString sp = new SpannableString(tvPrice.getText().toString());
            sp.setSpan(new RelativeSizeSpan(0.7f), tvPrice.getText().length() - 1, tvPrice.getText().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //0.5f表示
            tvPrice.setText(sp);
        } else {
            SpannableString sp = new SpannableString(tvPrice.getText().toString());
            sp.setSpan(new RelativeSizeSpan(0.7f), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //0.5f表示
            tvPrice.setText(sp);
        }
    }
}
